import { useUserStore } from '@/stores/index'
import  router  from '@/router/index'
import NProgress from 'nprogress'
NProgress.configure({
    showSpinner: false
  })
router.beforeEach((to,)=>{
    NProgress.start()
    document.title = `优医问诊-${to.meta.title || ''}`
    // 获取用户仓库
    const store = useUserStore()
    // 定义不需要登录的页面白名单
    const whiteList = ['/login','register']
    // 如果没有登录且不在白名单内就去登录页
    if(!store.user?.token && !whiteList.includes(to.path)){
        return '/login'
    }
})
router.afterEach(()=>{
    NProgress.done()
})
export default router